

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="一、设置phpMyAdmin自动登录首先在根目录找到config.sample.inc.php复制一份文件名改为config.inc.php（如果已经存在 config.inc.php 文件，则直接修改该文件即可）。打开config.inc.php 找到 $cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;]，将代码如下: 1$cfg[&amp;#x27;Serv">
<meta property="og:type" content="article">
<meta property="og:title" content="配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录">
<meta property="og:url" content="http://example.com/2017/04/02/mysql/%E9%85%8D%E7%BD%AEphpMyAdmin%E8%BF%9E%E6%8E%A5%E5%A4%9A%E5%8F%B0mysql%E6%9C%8D%E5%8A%A1%E5%99%A8/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="一、设置phpMyAdmin自动登录首先在根目录找到config.sample.inc.php复制一份文件名改为config.inc.php（如果已经存在 config.inc.php 文件，则直接修改该文件即可）。打开config.inc.php 找到 $cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;]，将代码如下: 1$cfg[&amp;#x27;Serv">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2017-04-02T05:24:12.000Z">
<meta property="article:modified_time" content="2022-02-10T03:13:09.982Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录 - Hexo</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.13","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>LZDF</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2017-04-02 13:24" pubdate>
        2017年4月2日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      17 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录</h1>
            
            <div class="markdown-body">
              <h1 id="一、设置phpMyAdmin自动登录"><a href="#一、设置phpMyAdmin自动登录" class="headerlink" title="一、设置phpMyAdmin自动登录"></a>一、设置phpMyAdmin自动登录</h1><p>首先在根目录找到<code>config.sample.inc.php</code>复制一份文件名改为<code>config.inc.php</code>（如果已经存在 <code>config.inc.php</code> 文件，则直接修改该文件即可）。<br>打开<code>config.inc.php</code> 找到 <code>$cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;]</code>，将代码如下:</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-variable">$cfg</span>[<span class="hljs-string">&#x27;Servers&#x27;</span>][<span class="hljs-variable">$i</span>][<span class="hljs-string">&#x27;auth_type&#x27;</span>] = <span class="hljs-string">&#x27;cookie&#x27;</span>;<br></code></pre></td></tr></table></figure>
<p>改成代码如下:</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-variable">$cfg</span>[<span class="hljs-string">&#x27;Servers&#x27;</span>][<span class="hljs-variable">$i</span>][<span class="hljs-string">&#x27;auth_type&#x27;</span>] = <span class="hljs-string">&#x27;config&#x27;</span>;<br></code></pre></td></tr></table></figure>
<p>然后在下面追加如下代码：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-variable">$cfg</span>[<span class="hljs-string">&#x27;Servers&#x27;</span>][<span class="hljs-variable">$i</span>][<span class="hljs-string">&#x27;user&#x27;</span>]          = <span class="hljs-string">&#x27;root&#x27;</span>;      <span class="hljs-comment">// 设置的mysql用户名</span><br><span class="hljs-variable">$cfg</span>[<span class="hljs-string">&#x27;Servers&#x27;</span>][<span class="hljs-variable">$i</span>][<span class="hljs-string">&#x27;password&#x27;</span>]      = <span class="hljs-string">&#x27;root&#x27;</span>;    <span class="hljs-comment">// 设置的mysql密码</span><br></code></pre></td></tr></table></figure>

<h1 id="二、设置phpMyAdmin连接多台Mysql服务器"><a href="#二、设置phpMyAdmin连接多台Mysql服务器" class="headerlink" title="二、设置phpMyAdmin连接多台Mysql服务器"></a>二、设置phpMyAdmin连接多台Mysql服务器</h1><p><em>默认安装phpMyAdmin，通常只能连一台MySql服务器，其配置信息是保存在phpMyAdmin的配置文件里的，当我们需要在多台服务器之间进行切换登陆的时候，修改起来非常麻烦。遵照下面的配置方法，我们可以方便的使用phpMyAdmin连接多台MySql</em></p>
<h4 id="特点："><a href="#特点：" class="headerlink" title="特点："></a>特点：</h4><p>登陆phpMyAdmin时只需输入用户名、密码，服务器地址为下拉列表可选，登陆后也可选择其他服务器快速切换。</p>
<h3 id="操作步骤："><a href="#操作步骤：" class="headerlink" title="操作步骤："></a>操作步骤：</h3><ol>
<li><p>备份phpMyAdmin根目录下的<code>config.sample.inc.php</code> 文件为 <code>config.sample.inc.php.bak</code>  (此操作避免修改失误所造成的损失)</p>
</li>
<li><p>备份phpMyAdmin根目录下的<code>config.inc.php</code> 文件为 <code>config.inc.php.bak</code>  (此操作避免修改失误所造成的损失)</p>
</li>
<li><p>将phpMyAdmin根目录下的<code>config.sample.inc.php</code> 文件重命名为<code>config.inc.php</code></p>
</li>
<li><p>修改<code>config.inc.php</code>文件，找到 <code>First server</code> 注释部分，将其修改为以下内容：</p>
</li>
</ol>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-variable">$hosts</span> = <span class="hljs-keyword">array</span>(<br>‘<span class="hljs-number">1</span>’=&gt;<span class="hljs-keyword">array</span>(‘host’=&gt;’localhost’,’user’=&gt;’root’,’password’=&gt;’<span class="hljs-number">123456</span>′),<br>‘<span class="hljs-number">2</span>’=&gt;<span class="hljs-keyword">array</span>(‘host’=&gt;’<span class="hljs-number">192.168</span>.<span class="hljs-number">0.1</span>′,’user’=&gt;’ciray’,’password’=&gt;’<span class="hljs-number">123456</span>′)<br>);<br></code></pre></td></tr></table></figure>
<p><code>$hosts</code>数组下标从1开始，<code>host</code>的值为服务器ip地址，<code>user</code>是对应的MySql登陆用户名，<code>password</code>的值为MySql的登陆密码，请修改成你自己的</p>
<p><code>$hosts</code>数组配置了两台服务器，如果你有多台服务器，请按数组下标递增的顺序添加配置信息</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-comment">/*</span><br><span class="hljs-comment"> * First server</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">for</span>(<span class="hljs-variable">$i</span> = <span class="hljs-number">1</span>; <span class="hljs-variable">$i</span> &lt;= count(<span class="hljs-variable">$hosts</span>); <span class="hljs-variable">$i</span>++)&#123;<br>    <span class="hljs-comment">/* Authentication type */</span><br>    <span class="hljs-variable">$cfg</span>[‘Servers’][<span class="hljs-variable">$i</span>][‘auth_type’] = ‘cookie<span class="hljs-string">&#x27;;</span><br><span class="hljs-string">    /* Server parameters */</span><br><span class="hljs-string">    $cfg[‘Servers’][$i][‘host’] = $hosts[$i][‘host’];   //修改host</span><br><span class="hljs-string">    $cfg[‘Servers’][$i][‘connect_type’] = ‘tcp&#x27;</span>;<br>    <span class="hljs-variable">$cfg</span>[‘Servers’][<span class="hljs-variable">$i</span>][‘compress’] = <span class="hljs-literal">false</span>;<br>    <span class="hljs-comment">/* Select mysqli if your server has it */</span><br>    <span class="hljs-variable">$cfg</span>[‘Servers’][<span class="hljs-variable">$i</span>][‘extension’] = ‘mysql<span class="hljs-string">&#x27;;</span><br><span class="hljs-string">    $cfg[‘Servers’][$i][‘AllowNoPassword’] = true;</span><br><span class="hljs-string">    $cfg[‘Servers’][$i][‘user’] = $hosts[$i][‘user’];  //修改用户名</span><br><span class="hljs-string">    $cfg[‘Servers’][$i][‘password’] = $hosts[$i][‘password’]; //密码</span><br><span class="hljs-string">&#125;</span><br></code></pre></td></tr></table></figure>
<p>请注意我们使用一个for循环来配置所有服务器的信息，循环变量$i的初始值为1，遍历<code>$hosts</code>数组中的配置信息，循环体中的内容无须更改。</p>
<p>修改完成后保存文件，重新登陆，如果可以看到phpMyAdmin登陆界面中出现服务器候选列表，说明修改正确</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/MySQL/">MySQL</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/MySQL/">MySQL</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2017/05/08/php/webuploder+PHP%E5%AE%9E%E7%8E%B0%E5%A4%A7%E6%96%87%E4%BB%B6%E6%96%AD%E7%82%B9%EF%BC%88%E5%88%87%E7%89%87%EF%BC%89%E7%BB%AD%E4%BC%A0/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">webuploder+PHP实现大文件断点（切片）续传</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2017/03/14/php/PHP%E7%9A%84%E5%86%92%E6%B3%A1%E7%AE%97%E6%B3%95/">
                        <span class="hidden-mobile">PHP的冒泡算法</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
